#!/bin/sh

case $1 in
w | 1)
        echo "mode W"
        uci set network.lan.ifname=eth0.1
        uci set network.@switch[0].enable_vlan=1
        uci set network.wan.ifname=eth0.2
        uci set network.wan6.ifname=eth0.2
        uci commit
        reg w 10000064 0x550
        reg w 1000003c 0xfe01ff
	echo 1 | dd bs=1 seek=1000 count=1 of=/dev/mtdblock1 2>/dev/null
        /etc/init.d/network restart      
        ;;
wllll | 2)
        echo "mode WLLLL"
        uci set network.lan.ifname=eth0.1
        uci set network.@switch[0].enable_vlan=1
        uci set network.wan.ifname=eth0.2
        uci set network.wan6.ifname=eth0.2
        uci commit
        reg w 10000064 0x0
        reg w 1000003c 0xe001ff
	echo 2 | dd bs=1 seek=1000 count=1 of=/dev/mtdblock1 2>/dev/null
        /etc/init.d/network restart      
        ;;
l | 3)
        echo "mode L"
        uci set network.lan.ifname=eth0
        uci set network.@switch[0].enable_vlan=0
        uci set network.wan.ifname=
        uci set network.wan6.ifname=
        uci commit
        reg w 10000064 0x550
        reg w 1000003c 0xfe01ff
	echo 3 | dd bs=1 seek=1000 count=1 of=/dev/mtdblock1 2>/dev/null
        /etc/init.d/network restart      
        ;;
lllll | 4)
        echo "mode LLLLL"
        uci set network.lan.ifname=eth0
        uci set network.@switch[0].enable_vlan=0
        uci set network.wan.ifname=
        uci set network.wan6.ifname=
        uci commit
        reg w 10000064 0x0
        reg w 1000003c 0xe001ff
	echo 4 | dd bs=1 seek=1000 count=1 of=/dev/mtdblock1 2>/dev/null
        /etc/init.d/network restart      
        ;;
*)
	echo "ethmode w/l/wllll/lllll"
	;;
esac
